DEFINITION FOR LIBRARY MODULE LowLevel ;

FROM SYSTEM	IMPORT ADDRESS, LONGSET ;
FROM Utility	IMPORT TAG_USER, Tag, TagItemPtr ;
FROM Timer	IMPORT EClockValPtr ;
FROM Exec	IMPORT LibraryPtr ;

(*===========================================================================*)

(* structure for use with QueryKeys() *)

TYPE
  KeyQueryPtr =  POINTER TO KeyQuery ;
  KeyQuery = RECORD
    kq_KeyCode : CARDINAL ;
    kq_Pressed : CARDINAL ;
  END ;

(*============================================================================*)

CONST
(* bits in the return value of GetKey() *)
  LLKB_LSHIFT	= 16 ;  LLKF_LSHIFT	= {LLKB_LSHIFT} ;
  LLKB_RSHIFT	= 17 ;  LLKF_RSHIFT	= {LLKB_RSHIFT} ;
  LLKB_CAPSLOCK	= 18 ;  LLKF_CAPSLOCK	= {LLKB_CAPSLOCK} ;
  LLKB_CONTROL	= 19 ;  LLKF_CONTROL	= {LLKB_CONTROL} ;
  LLKB_LALT	= 20 ;  LLKF_LALT	= {LLKB_LALT} ;
  LLKB_RALT	= 21 ;  LLKF_RALT	= {LLKB_RALT} ;
  LLKB_LAMIGA	= 22 ;  LLKF_LAMIGA	= {LLKB_LAMIGA} ;
  LLKB_RAMIGA	= 23 ;  LLKF_RAMIGA	= {LLKB_RAMIGA} ;

(*============================================================================*)

(* Tags for SetJoyPortAttrs() *)
  SJA_Dummy	   = TAG_USER+0C00100H ;
  SJA_Type	   = SJA_Dummy+1 ; (* force type to mouse, joy, game cntrlr *)
  SJA_Reinitialize = SJA_Dummy+2 ; (* free potgo bits, reset to autosense   *)

(* Controller types for SJA_Type tag *)
  SJA_TYPE_AUTOSENSE = 0 ;
  SJA_TYPE_GAMECTLR  = 1 ;
  SJA_TYPE_MOUSE     = 2 ;
  SJA_TYPE_JOYSTK    = 3 ;

(*============================================================================*)

(* ReadJoyPort() return value definitions *)

(* Port types *)
  JP_TYPE_NOTAVAIL	= 0		    ; (* port data unavailable    *)
  JP_TYPE_GAMECTLR	= LONGINT({28})	    ; (* port has game controller *)
  JP_TYPE_MOUSE		= LONGINT({29})	    ; (* port has mouse		  *)
  JP_TYPE_JOYSTK	= LONGINT({28,29})  ; (* port has joystick	  *)
  JP_TYPE_UNKNOWN  	= LONGINT({30})	    ; (* port has unknown device  *)
  JP_TYPE_MASK		= LONGINT({28..31}) ; (* controller type	  *)

(* Button types, valid for all types except JP_TYPE_NOTAVAIL *)
  JPB_BUTTON_BLUE    = 23 ; (* Blue - Stop; Right Mouse		       *)
  JPB_BUTTON_RED     = 22 ; (* Red - Select; Left Mouse; Joystick Fire *)
  JPB_BUTTON_YELLOW  = 21 ; (* Yellow - Repeat			       *)
  JPB_BUTTON_GREEN   = 20 ; (* Green - Shuffle			       *)
  JPB_BUTTON_FORWARD = 19 ; (* Charcoal - Forward		       *)
  JPB_BUTTON_REVERSE = 18 ; (* Charcoal - Reverse		       *)
  JPB_BUTTON_PLAY    = 17 ; (* Grey - Play/Pause; Middle Mouse	       *)

  JPF_BUTTON_BLUE    = {JPB_BUTTON_BLUE} ;
  JPF_BUTTON_RED     = {JPB_BUTTON_RED} ;
  JPF_BUTTON_YELLOW  = {JPB_BUTTON_YELLOW} ;
  JPF_BUTTON_GREEN   = {JPB_BUTTON_GREEN} ;
  JPF_BUTTON_FORWARD = {JPB_BUTTON_FORWARD} ;
  JPF_BUTTON_REVERSE = {JPB_BUTTON_REVERSE} ;
  JPF_BUTTON_PLAY    = {JPB_BUTTON_PLAY} ;
  JP_BUTTON_MASK     = JPF_BUTTON_BLUE+JPF_BUTTON_RED+JPF_BUTTON_YELLOW
  			+JPF_BUTTON_GREEN+JPF_BUTTON_FORWARD+JPF_BUTTON_REVERSE
  			+JPF_BUTTON_PLAY ;

(* Direction types, valid for JP_TYPE_GAMECTLR and JP_TYPE_JOYSTK *)
  JPB_JOY_UP	    = 3 ;
  JPB_JOY_DOWN	    = 2 ;
  JPB_JOY_LEFT	    = 1 ;
  JPB_JOY_RIGHT	    = 0 ;
  JPF_JOY_UP	    = {JPB_JOY_UP} ;
  JPF_JOY_DOWN	    = {JPB_JOY_DOWN} ;
  JPF_JOY_LEFT	    = {JPB_JOY_LEFT} ;
  JPF_JOY_RIGHT	    = {JPB_JOY_RIGHT} ;
  JP_DIRECTION_MASK = JPF_JOY_UP+JPF_JOY_DOWN+JPF_JOY_LEFT+JPF_JOY_RIGHT ;

(* Mouse position reports, valid for JP_TYPE_MOUSE *)
  JP_MHORZ_MASK	= {0..7} ;	(* horzizontal position *)
  JP_MVERT_MASK	= {8..15} ;	(* vertical position	*)
  JP_MOUSE_MASK	= JP_MHORZ_MASK+JP_MVERT_MASK ;

(* Obsolete ReadJoyPort() definitions,here for source code compatibility only *)
(* Please do NOT use in new code.					      *)

CONST
  JPB_BTN1  = JPB_BUTTON_BLUE ;
  JPF_BTN1  = JPF_BUTTON_BLUE ;
  JPB_BTN2  = JPB_BUTTON_RED ;
  JPF_BTN2  = JPF_BUTTON_RED ;
  JPB_BTN3  = JPB_BUTTON_YELLOW ;
  JPF_BTN3  = JPF_BUTTON_YELLOW ;
  JPB_BTN4  = JPB_BUTTON_GREEN ;
  JPF_BTN4  = JPF_BUTTON_GREEN ;
  JPB_BTN5  = JPB_BUTTON_FORWARD ;
  JPF_BTN5  = JPF_BUTTON_FORWARD ;
  JPB_BTN6  = JPB_BUTTON_REVERSE ;
  JPF_BTN6  = JPF_BUTTON_REVERSE ;
  JPB_BTN7  = JPB_BUTTON_PLAY ;
  JPF_BTN7  = JPF_BUTTON_PLAY ;
  JPB_UP    = JPB_JOY_UP ;
  JPF_UP    = JPF_JOY_UP ;
  JPB_DOWN  = JPB_JOY_DOWN ;
  JPF_DOWN  = JPF_JOY_DOWN ;
  JPB_LEFT  = JPB_JOY_LEFT ;
  JPF_LEFT  = JPF_JOY_LEFT ;
  JPB_RIGHT = JPB_JOY_RIGHT ;
  JPF_RIGHT = JPF_JOY_RIGHT ;

(*============================================================================*)

(* Tags for SystemControl() *)
  SCON_Dummy		= TAG_USER+000C00000H ;
  SCON_TakeOverSys	= SCON_Dummy+0 ;
  SCON_KillReq		= SCON_Dummy+1 ;
  SCON_CDReboot		= SCON_Dummy+2 ;
  SCON_StopInput	= SCON_Dummy+3 ;
  SCON_AddCreateKeys	= SCON_Dummy+4 ;
  SCON_RemCreateKeys	= SCON_Dummy+5 ;

(* Reboot control values for use with SCON_CDReboot tag *)
  CDReboot_On		= 1 ;
  CDReboot_Off		= 0 ;
  CDReboot_Default	= 2 ;

(*============================================================================*)

(* Rawkey codes returned when using SCON_AddCreateKeys with SystemControl() *)

CONST
  RAWKEY_PORT0_BUTTON_BLUE	= 072H ;
  RAWKEY_PORT0_BUTTON_RED	= 078H ;
  RAWKEY_PORT0_BUTTON_YELLOW	= 077H ;
  RAWKEY_PORT0_BUTTON_GREEN	= 076H ;
  RAWKEY_PORT0_BUTTON_FORWARD	= 075H ;
  RAWKEY_PORT0_BUTTON_REVERSE	= 074H ;
  RAWKEY_PORT0_BUTTON_PLAY	= 073H ;
  RAWKEY_PORT0_JOY_UP		= 079H ;
  RAWKEY_PORT0_JOY_DOWN		= 07AH ;
  RAWKEY_PORT0_JOY_LEFT		= 07CH ;
  RAWKEY_PORT0_JOY_RIGHT	= 07BH ;

  RAWKEY_PORT1_BUTTON_BLUE	= 0172H ;
  RAWKEY_PORT1_BUTTON_RED	= 0178H ;
  RAWKEY_PORT1_BUTTON_YELLOW	= 0177H ;
  RAWKEY_PORT1_BUTTON_GREEN	= 0176H ;
  RAWKEY_PORT1_BUTTON_FORWARD	= 0175H ;
  RAWKEY_PORT1_BUTTON_REVERSE	= 0174H ;
  RAWKEY_PORT1_BUTTON_PLAY	= 0173H ;
  RAWKEY_PORT1_JOY_UP		= 0179H ;
  RAWKEY_PORT1_JOY_DOWN		= 017AH ;
  RAWKEY_PORT1_JOY_LEFT		= 017CH ;
  RAWKEY_PORT1_JOY_RIGHT	= 017BH ;

  RAWKEY_PORT2_BUTTON_BLUE	= 0272H ;
  RAWKEY_PORT2_BUTTON_RED	= 0278H ;
  RAWKEY_PORT2_BUTTON_YELLOW	= 0277H ;
  RAWKEY_PORT2_BUTTON_GREEN	= 0276H ;
  RAWKEY_PORT2_BUTTON_FORWARD	= 0275H ;
  RAWKEY_PORT2_BUTTON_REVERSE	= 0274H ;
  RAWKEY_PORT2_BUTTON_PLAY	= 0273H ;
  RAWKEY_PORT2_JOY_UP		= 0279H ;
  RAWKEY_PORT2_JOY_DOWN		= 027AH ;
  RAWKEY_PORT2_JOY_LEFT		= 027CH ;
  RAWKEY_PORT2_JOY_RIGHT	= 027BH ;

  RAWKEY_PORT3_BUTTON_BLUE	= 0372H ;
  RAWKEY_PORT3_BUTTON_RED	= 0378H ;
  RAWKEY_PORT3_BUTTON_YELLOW	= 0377H ;
  RAWKEY_PORT3_BUTTON_GREEN	= 0376H ;
  RAWKEY_PORT3_BUTTON_FORWARD	= 0375H ;
  RAWKEY_PORT3_BUTTON_REVERSE	= 0374H ;
  RAWKEY_PORT3_BUTTON_PLAY	= 0373H ;
  RAWKEY_PORT3_JOY_UP		= 0379H ;
  RAWKEY_PORT3_JOY_DOWN		= 037AH ;
  RAWKEY_PORT3_JOY_LEFT		= 037CH ;
  RAWKEY_PORT3_JOY_RIGHT	= 037BH ;

(*============================================================================*)

(* Return values for GetLanguageSelection() *)
CONST
  LANG_UNKNOWN	  =  0 ;
  LANG_AMERICAN	  =  1 ; (* American English *)
  LANG_ENGLISH	  =  2 ; (* British English  *)
  LANG_GERMAN	  =  3 ;
  LANG_FRENCH	  =  4 ;
  LANG_SPANISH	  =  5 ;
  LANG_ITALIAN	  =  6 ;
  LANG_PORTUGUESE =  7 ;
  LANG_DANISH	  =  8 ;
  LANG_DUTCH	  =  9 ;
  LANG_NORWEGIAN  = 10 ;
  LANG_FINNISH	  = 11 ;
  LANG_SWEDISH	  = 12 ;
  LANG_JAPANESE	  = 13 ;
  LANG_CHINESE	  = 14 ;
  LANG_ARABIC	  = 15 ;
  LANG_GREEK	  = 16 ;
  LANG_HEBREW	  = 17 ;
  LANG_KOREAN	  = 18 ;

(*============================================================================*)

VAR
  LowLevelBase : LibraryPtr ;

(*--- functions in V40 or higher (Release 3.1) ---*)

(* CONTROLLER HANDLING *)

PROCEDURE ReadJoyPort( port : LONGINT ) : LONGINT ;

(* LANGUAGE HANDLING *)

PROCEDURE GetLanguageSelection( ) : SHORTINT ;

(* KEYBOARD HANDLING *)

PROCEDURE GetKey( ) : LONGSET ;
PROCEDURE QueryKeys( queryArray : KeyQueryPtr ; arraySize : LONGINT ) ;
PROCEDURE AddKBInt( intRoutine , intData : ADDRESS ) : ADDRESS ;
PROCEDURE RemKBInt( intHandle : ADDRESS  );

(* SYSTEM HANDLING *)

PROCEDURE SystemControlA( tagList : TagItemPtr ) : LONGINT ;
PROCEDURE SystemControl( firstTag : Tag ; .. ) : LONGINT ;

(* TIMER HANDLING *)

PROCEDURE AddTimerInt( intRoutine : ADDRESS ; intData : ADDRESS ) : ADDRESS ;
PROCEDURE RemTimerInt( intHandle : ADDRESS ) ;
PROCEDURE StopTimerInt( intHandle : ADDRESS ) ;
PROCEDURE StartTimerInt( intHandle : ADDRESS ;
			 timeInterval : LONGINT ;
			 continuous : LONGINT );

PROCEDURE ElapsedTime( context : EClockValPtr ) : LONGINT ;

(* VBLANK HANDLING *)

PROCEDURE AddVBlankInt( intRoutine, intData : ADDRESS ) : ADDRESS ;
PROCEDURE RemVBlankInt( intHandle : ADDRESS ) ;

(* MORE CONTROLLER HANDLING *)

PROCEDURE SetJoyPortAttrsA( portNumber : LONGINT ;
			    tagList : TagItemPtr ) : BOOLEAN ;

PROCEDURE SetJoyPortAttrs( portNumber : LONGINT ;
			   firstTag : Tag ; .. ) : BOOLEAN ;

END LowLevel.
